package com.health.es.temp;

import com.health.es.util.ElasticsearchRestTemplate;
import com.health.es.util.SearchHits;
import com.health.es.util.query.Query;
import com.health.es.util.repository.support.ElasticsearchEntityInformation;
import com.health.es.util.repository.support.SimpleElasticsearchRepository;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.index.query.QueryBuilder;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import java.util.List;

/**
 * @author nqlz
 */
@Slf4j
public class EsCustomImpl<T, ID> extends SimpleElasticsearchRepository<T, ID> implements EsCustomRepository<T, ID> {

    public EsCustomImpl(ElasticsearchEntityInformation<T, ID> metadata, ElasticsearchRestTemplate operations) {
        super(metadata, operations);
        EsHelper.operations = operations;
    }

    @Override
    public List<T> selectList(Query query) {
        return EsHelper.search(entityClass, query);
    }

    @Override
    public List<T> selectList(SFunction<QueryWrapper<T>, QueryWrapper<T>> wrapper) {
        return EsHelper.search(entityClass, wrapper);
    }

    @Override
    public List<T> selectList(QueryBuilder... builders) {
        return EsHelper.search(entityClass, builders);
    }

    @Override
    public List<T> selectList(Sort sort, QueryBuilder... builders) {
        return EsHelper.search(entityClass, sort, builders);
    }

    @Override
    public T searchOne(Query query) {
        return EsHelper.searchOne(entityClass, query);
    }

    @Override
    public T searchOne(QueryBuilder... builders) {
        return EsHelper.searchOne(entityClass, builders);
    }

    @Override
    public T searchOne(SFunction<QueryWrapper<T>, QueryWrapper<T>> wrapper) {
        return EsHelper.searchOne(entityClass, wrapper);
    }

    @Override
    public EsPage<T> searchPage(Pageable pageable, QueryBuilder... builders) {
        return EsHelper.searchPage(entityClass, pageable, builders);
    }

    @Override
    public EsPage<T> searchPage(SFunction<QueryWrapper<T>, QueryWrapper<T>> wrapper) {
        return EsHelper.searchPage(entityClass, wrapper);
    }

    @Override
    public SearchHits<T> prime(SFunction<QueryWrapper<T>, QueryWrapper<T>> wrapper) {
        return EsHelper.prime(entityClass, wrapper);
    }

}
